import { defaultParams } from "@/interface/public";
import http from "@/api";
import { PORT3 } from "@/api/config/servicePort";
import { Dictionary, System } from "@/api/interface/auth/basic";

/**
 * @name 基础资料
 */
// 系统设置项
export const systemList = () => http.get(PORT3 + `/system/list`);

// 系统设置项保存
export const systemSave = (params: System.ReqSave) => http.post(PORT3 + `/system/save`, params);

// dictionary/typeList
// ----------------字典--------------------
const DICTIONARY_PORT = PORT3 + "/dictionary";
// 查询系统下所有字典目录
export const dictionaryTypeList = (params: { code: string }) =>
  http.get<Array<string>>(DICTIONARY_PORT + `/typeList/${params.code}`);

// 得到系统内目录下的字典名称
export const dictionaryCodeListByType = (params: { type: string }) =>
  http.get<Dictionary.ResGetCatalogByType[]>(DICTIONARY_PORT + `/codeListByType`, params);

// 保存字典值
export const dictionarySave = (params: Dictionary.ReqSave) => http.post(DICTIONARY_PORT + `/save`, params);

// 删除字典值
export const dictionaryRemove = (params: defaultParams) => http.post<Array<string>>(DICTIONARY_PORT + `/remove/${params.id}`);

// 启用字典
export const dictionaryEnable = (params: defaultParams) => http.post(DICTIONARY_PORT + `/enable/${params.id}`);

// 禁用字典
export const dictionaryDisable = (params: defaultParams) => http.post(DICTIONARY_PORT + `/disable/${params.id}`);

// 查询字典值
export const dictionaryListByCodes = (params: { code: string }) =>
  http.get<Dictionary.ResSearch[]>(DICTIONARY_PORT + `/listByCodes`, params);

// 多个请求同时请求
export const promiseAllApi = async (reqArr: Array<Promise<unknown>>) => {
  const resArr = await Promise.all(reqArr);
  return resArr;
};
